<?php

/* Author: Panos Sakkos
 * Creates and enables the given category
 */

function admin_create_category($category, $userId)
{
    $owner = getUserData($userId);
    $error = DB_addCategory($category->GetName(), $userId);

    if ($error < 0)
    {
        return BL_ADMIN_ADD_CATEGORY;
    }

    $categoryId = $error;
    $attrs = $category->GetAttributes();
    $count = count($attrs);

    for ($i = 0; $i < $count; $i++)
    {
        $error = DB_addAttributeToCategory($attrs[$i], $category->GetId());

        if ($error != DB_OK)
        {
            return BL_ADD_ATTRIBUTE_TO_CATEGORY;
        }
    }

    $err_no = DB_enableCategory($categoryId);

    return $err_no >= 0 ? BL_OK : BL_ADMIN_ENABLE_CATEGORY;
}

?>